<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/css/public.css" media="all">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="js/lay-config.js?v=2.0.0" charset="utf-8"></script>
    <script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>

    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layuimini-container" style="width: 800; height: 600px;">
        <div class="layuimini-main">
            <fieldset class="table-search-fieldset">
                <legend>搜索信息</legend>
                <div style="margin: 10px 10px 10px 10px">
                    <form class="layui-form layui-form-pane" action="" id="armarium_fm">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">序号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="armarium_id" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">设备名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="armarium_name" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">型号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="armarium_num" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">投入科室</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="armarium_department" autocomplete="off"
                                        class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>


            <table class="layui-hide" id="armariumTable" lay-filter="currentTableFilter"></table>

            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-normal layui-btn-sm layui-btn-radius data-add-btn" lay-event="add"> 添加 </button>
                    <button class="layui-btn layui-btn-sm layui-btn-warm layui-btn-radius data-delete-btn" lay-event="delete">批量 删除 </button>
                    <button class="layui-btn layui-btn-sm layui-btn-radius data-delete-btn" lay-event="import"> 导入 </button>
                    <button class="layui-btn layui-btn-sm layui-btn-normal layui-btn-radius data-delete-btn" lay-event="export"> 导出 </button>
                    <button class="layui-btn layui-btn-sm layui-btn-radius data-delete-btn" lay-event="templetdownload"> 模板下载 </button>
                    <button class="layui-btn layui-btn-sm layui-btn-warm layui-btn-radius data-delete-btn" lay-event="bar"> 柱状图 </button>
                </div>
            </script>

            <table class="layui-hide" id="armariumTableId" lay-filter="currentTableFilter"></table>

            <script type="text/html" id="currentTableBar">
                <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
            </script>

        </div>
    </div>
    <script id="pic">
        <img src="{{d.armarium_img}}" name="armarium_img" style="width:100%; height:100%;" />
    </script>
    <script>
        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;

            table.render({
                elem: '#armariumTableId',
                url: 'http://localhost:8080/medical/armarium/list',
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [[
                    { type: "checkbox", width: 50 },
                    { field: 'armarium_id', width: 100, title: '序号', sort: true },
                    { field: 'armarium_name', width: 150, title: '设备名称' },
                    { field: 'armarium_num', width: 100, title: '型号' },
                    { field: 'armarium_type', width: 100, title: '单位' },
                    { field: 'armarium_amount', width: 100, title: '数量', sort: true },
                    { field: 'armarium_unit', width: 100, title: '单价', sort: true },
                    { field: 'armarium_department', width: 150, title: '投入科室' },
                    { field: 'armarium_img', width: 135, title: '图片', templet: '#pic' },
                    { title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center" }
                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 10,
                page: true,
                skin: 'line'
            });

            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                // debugger
                var result = JSON.stringify(data.field);
                // var result = data.alist
                // layer.alert(result, {
                //     title: '最终的搜索信息'
                // });

                //执行搜索重载
                table.reload('armariumTableId', {
                    page: {
                        curr: 1
                    }
                    , where: {
                        // hid: data.field.hid,
                        armarium_id: data.field.armarium_id,
                        armarium_name: data.field.armarium_name,
                        armarium_num: data.field.armarium_num,
                        armarium_department: data.field.armarium_department,
                    }
                }, 'data');
                // debugger
                return false;
            });

            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                if (obj.event === 'add') {  // 监听添加操作
                    var index = layer.open({
                        title: '添加设备',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['80%', '100%'],
                        content: '/page/medical/armarium/armariumadd.html',
                        end: function (index) {
                            table.reload('armariumTableId');
                        }
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                } else if (obj.event === 'delete') {  // 监听删除操作
                    var checkStatus = table.checkStatus('armariumTableId')
                        , data = checkStatus.data;
                    var selectids = new Array();
                    var count = 0;
                    $.each(data, function (index, value) {
                        selectids[count] = value.armarium_id;
                        count++;
                        console.log(index, value.armarium_id);
                    })
                    var ids = encodeURI(selectids);
                    if (selectids.length != 0) {
                        //JSON.stringify(ids) 把对象转换成json字符串
                        //JSON.parse() 把json字符串转对象
                        //layer.alert(JSON.stringify(ids));
                        console.log("armarium_id" + ids),
                            $.post("http://localhost:8080/medical/armarium/deleteIds", { armarium_ids: ids },
                                function (res) {
                                    // var result = JSON.parse(res);//{"code":1,"msg":"删除选中用户成功！"}
                                    //layer.alert("code:"+result.code);
                                    if (res.code == 0) {
                                        //layer.alert(result.msg);
                                        //layui.table.reload('userTable');//数据表格的id
                                        layer.msg("批量删除成功", { icon: 1, time: 2000 },
                                        // layui.table.reload('armariumTableId')
                                            function () { setTimeout("parent.location.reload();", 200); });
                                    } else {
                                        layer.alert("批量删除失败", { icon: 5, time: 2000 });
                                    }
                                }, "json");
                    } else {
                        layer.alert("没有选中任何用户信息！", { icon: 2, time: 2000 });
                    }

                    // layer.alert(JSON.stringify(data));
                }else if(obj.event === 'bar'){
                    layer.open({
                        title: '柱状图',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['50%', '90%'],
                        content: 'amariumbar.html',
                    })

                }else if(obj.event === 'export'){//导出
                    // layer.open({
                    //    title: "导出"
                    // })
                    location.href = "http://localhost:8080/medical/armarium/export?"+$("#armarium_fm").serialize();


                }else if(obj.event === 'import'){//导入
                    layer.open({
                        title: '医疗设备信息导入',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['35%', '40%'],
                        content: '/page/medical/armarium/armariumImport.html',
                        end: function (index) {
                            table.reload('armariumTableId');
                        }
                    })


                }else if(obj.event === 'templetdownload'){
                    // layer.open({
                    //     title:"xia"
                    // })
                    location.href = "http://localhost:8080/medical/armarium/templetDownload"

                }
            });

            //监听表格复选框选择
            table.on('checkbox(currentTableFilter)', function (obj) {
                console.log(obj)
            });

            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {
                    //把要修改的数据存到 localStorage        跳转到修改页面之后  再取出来 
                    localStorage.setItem("armarium", JSON.stringify(data));

                    var index = layer.open({
                        title: '编辑设备信息',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['80%', '100%'],
                        content: '/page/medical/armarium/armariumedit.html',
                        end: function (index) {
                            table.reload('armariumTableId');
                        }
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                    return false;
                } else if (obj.event === 'delete') {
                    layer.confirm('真的删除行么', function (index) {
                        $.get("http://localhost:8080/medical/armarium/delete", { armarium_id: data.armarium_id }, function (result) {
                            if (result.code == 0) {
                                layer.msg("删除成功", { icon: 1, time: 2000 },
                                    function () { setTimeout("layui.table.reload()", 2000); });
                                obj.del();//删除页面对应的数据

                            }
                        }, "json");

                        layer.close(index);
                    });
                }
            });

        });
    </script>

</body>

</html>